/**
 * \* Created with IntelliJ IDEA.
 * \* User: Administrator
 * \* Date: 2021/11/13
 * \* Time: 16:40
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */

class  ListNode{
    public int val;
    public ListNode next;

    public ListNode(int val){
        this.val=val;
    }
}
public class MyList {
    public ListNode head;//代表链表的头引用

    public void createList(){
        ListNode listNode1 = new ListNode(12);
        ListNode listNode2 = new ListNode(23);
        ListNode listNode3 = new ListNode(34);
        ListNode listNode4 = new ListNode(45);
        ListNode listNode5 = new ListNode(56);
        ListNode listNode6 = new ListNode(67);

        listNode1.next=listNode2;
        listNode2.next=listNode3;
        listNode3.next=listNode4;
        listNode4.next=listNode5;
        listNode5.next=listNode6;
        this.head=listNode1;

    }

    public ListNode display(int key){
        if(this.head==null){
            return null ;
        }
        ListNode prev=this.head;
        ListNode cur=this.head.next;

        while(cur!=null){
            if(cur.val==key){
                prev.next=cur.next;
                cur=cur.next;
            }else{
                prev=cur;
                cur=cur.next;
            }

        }
        if(this.head.val==key){
            this.head=this.head.next;
        }
        return head;
    }

}
